let db = require('../db/index')

exports.get = (req,res) =>{//通过姓名查询数据
    var sql = "select * from project where pname like '%' ?"
    db.query(sql,[req.query.pname],(err,data)=>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })
}

exports.del = (req,res) =>{//通过姓名删除数据
    var sql = 'delete from project where pname = ?'
    db.query(sql,[req.query.pname],(err,data) =>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })

}

exports.add = (req,res)=>{
    var sql = 'insert into project (pname,pdescription,time,user,id) values (?,?,?,?,?)'
    db.query(sql, [req.query.pname,req.query.pdescription,req.query.time,req.query.user,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}

exports.update = (req,res)=>{
    var sql = 'update project set pname = ? ,pdescription = ?,time = ?,user = ? where id = ?'
    db.query(sql, [req.query.pname,req.query.pdescription,req.query.time,req.query.user,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}